package com.yoomiito.app.ui.order.list

import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseLazyFragmentPresenter
import com.yoomiito.app.model.bean.OrderList
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.utils.NetworkUtils

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi

class OrderFmPresenter(appConfig: AppConfig) : BaseLazyFragmentPresenter<OrderFragment>(appConfig) {

    fun queryOrderList(orderType: Int, page: Int) {
        if (NetworkUtils.checkNetPermission(v.context)) {
            v.finishRefresh()
            return
        }
        YmApi.getYmService()
                .queryOrderList(1,orderType, page)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData<OrderList>())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<OrderList>() {
                    override fun onSuccess(orderList: OrderList) {
                        if (hasV())
                            v.setData(orderList)
                    }

                    override fun onFail(error: ApiException) {

                    }
                })
    }
}
